Skip to content

feat(editor): attach reference images to agent requests and pin to brief (#1027) - #1233

Open
houko wants to merge 2 commits into
mainfrom
feat/editor-reference-images-1027
Open

houko wants to merge 2 commits into
mainfrom
feat/editor-reference-images-1027

Conversation

@houko

@houko houko commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements attaching PNG, JPEG, and WebP reference images to Agent composer requests and pinning them to the project's brief.yaml, matching docs/design/editor/Sketch.dc.html (Paste or drop an image, Pin to brief) using exclusively docs/design/editor/Spec.dc.html tokens.

Closes #1027.

Key changes

  • Reference image validation, drop, paste, and one-shot delivery (packages/game/editor/agent_references.go, agent.go, agent_runner_desktop.go, state.go, commands.go):
    • Added strict in-memory PNG, JPEG, and WebP magic-byte + pixel decoding (DecodeAgentReferenceImage, using image/png, image/jpeg, and golang.org/x/image/webp) under bounded size and pixel limits; unsupported types (GIF, SVG, BMP, PDF, text, or corrupted files) are refused with an explicit reason.
    • Wired drag-and-drop (OnFileDragEnter, OnFileDragLeave, OnFileDrop → DropAgentReferenceFiles), composer paste (core.Input.OnPaste → HandleAgentComposerPaste, plus PasteAgentReferenceImage with injectable ReadClipboardImage / ReadClipboardFiles hooks), and the composer attach button (PickAndAttachAgentReferenceImages / CmdAttachReferenceImage with injectable PickAgentReferenceFiles).
    • Extended AgentRequest (AttachedImages, BriefImages, Images) and AgentTurn (Images): SubmitAgentPrompt snapshots one-shot attachments and pinned brief.yaml references (deduplicated by path) and immediately clears one-shot attachments so the next request never carries them.
  • Atomic undoable Pin to brief & Always chip (packages/game/editor/agent_references.go, agent_references_ui.go, agent_ui.go):
    • PinAgentReferenceImage executes an atomic fallibleCommand (pinReferenceImageCmd) on Editor.History that copies the image to art/reference/<name> (disambiguating filename collisions without overwriting different files), appends - path: art/reference/<name> (plus optional note:) under art.references in brief.yaml via yaml.Node AST editing (preserving existing keys and comments), refreshes the project file index and Changes/Review panel, and shows the Pin to brief confirmation card with a monospace + YAML diff and Undo button.
    • A single Undo removes both art/reference/<name> and the added brief.yaml entry (or removes a freshly created brief.yaml and empty art/reference/ directory); Redo restores both cleanly.
    • Added attached image chips (32×24 thumbnail, filename, Pin to brief / Pinned toggle, × remove), hover/focus preview popover above the composer, "Drop to attach" drag-over target, refusal alert banner, Always brief.yaml chip with pinned reference count and hover preview, and user turn thumbnail strip—styled strictly with SpecPalette tokens in both Dark and Light appearances.
  • Locales, docs, changelog, and agent note:
    • Added strictly sorted EN/ZH strings in packages/game/editor/locales/{en,zh}.yaml.
    • Updated docs/en/editor.md and docs/zh/editor.md.
    • Added changelog.d/editor-reference-images-1027.md and .agents/notes/implemented/feature/2026-11-26-editor-agent-reference-images.md.

Verification

  • env -u GOROOT go tool nsgo check ./editor and env -u GOROOT go tool nsgo check -target ios ./editor (passed)
  • env -u GOROOT go tool nsgo check ./editor/editorcmd and env -u GOROOT go tool nsgo check -target ios ./editor/editorcmd (passed)
  • TMPDIR=/tmp env -u GOROOT go tool nsgo test ./editor -run 'TestLocaleCatalogsComplete|TestAgent|TestConnectDialog|TestBuildCLIArgs|TestDesktopMenuBarMatchesRegistryAndExecutesActions' (16 passed)
  • TMPDIR=/tmp env -u GOROOT go tool nsgo test ./editor/editorcmd -run TestAgentReferenceImagesMacOSScreenshots (passed headless)
  • TMPDIR=/tmp env -u GOROOT go tool nsgo test -target macos -screenshots .nsgo/test/screenshots/macos -run TestAgentReferenceImagesMacOSScreenshots ./editor/editorcmd — captured and visually inspected all 4 macOS screenshots (composer-attached-preview, composer-drop-zone, composer-pinned-diff, composer-refused-type) beside Sketch.dc.html, then removed temporary PNGs
  • bun run verify-notes and env -u GOROOT go run ./tools/changelog check (passed)

@github-actions github-actions Bot added conflict Conflicts with the target branch; resolve before merging enhancement New feature or request size/XL documentation Improvements or additions to documentation pkg/editor area/agents and removed size/XL labels Nov 26, 2026
@houko
houko force-pushed the feat/editor-reference-images-1027 branch from 4979b3e to 7c41a56 Compare November 26, 2026 11:17
@github-actions github-actions Bot added area/website size/XL conflict Conflicts with the target branch; resolve before merging and removed conflict Conflicts with the target branch; resolve before merging labels Nov 26, 2026
@houko
houko force-pushed the feat/editor-reference-images-1027 branch from 7c41a56 to b6f53ea Compare November 26, 2026 12:04
@github-actions github-actions Bot added conflict Conflicts with the target branch; resolve before merging and removed conflict Conflicts with the target branch; resolve before merging labels Nov 26, 2026
@houko
houko force-pushed the feat/editor-reference-images-1027 branch from b6f53ea to 14986e1 Compare November 26, 2026 12:30
@github-actions github-actions Bot added conflict Conflicts with the target branch; resolve before merging and removed conflict Conflicts with the target branch; resolve before merging labels Nov 26, 2026
@houko
houko force-pushed the feat/editor-reference-images-1027 branch from 14986e1 to 3ff2ca6 Compare November 26, 2026 13:00
@github-actions github-actions Bot added conflict Conflicts with the target branch; resolve before merging and removed conflict Conflicts with the target branch; resolve before merging labels Nov 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agents area/website conflict Conflicts with the target branch; resolve before merging documentation Improvements or additions to documentation enhancement New feature or request pkg/editor size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: attach reference images to an agent request and pin them to the brief

1 participant